package jmp123.shell.vo;

import java.io.File;
import jmp123.shell.util.MP3Info;
import jmp123.shell.util.MP3Util;

public class Song {

	private MP3Info tag;
	private String path;

	public MP3Info getTag() {
		if (this.tag == null) {
			try {
				File f = new File(this.path);
				this.tag = MP3Util.getInfo(f);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return tag;
	}

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

	@Override
	public String toString() {
		return this.getTag().getName();
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((path == null) ? 0 : path.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Song other = (Song) obj;
		if (path == null) {
			if (other.path != null)
				return false;
		} else if (!path.equals(other.path))
			return false;
		return true;
	}

}
